package performanceTest;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;

import org.junit.Before;
import org.junit.Test;

public class PerformanceTestArrayList {
	
//	private int count = 20_000_000;
	private int count = 1000_000;
	private List<String> list = new ArrayList<>(count);
	
	@Before
	public void init(){
		for(int i = 0; i < count; i++){
			list.add(String.valueOf(i));
		}
	}

	@Test
	public void iterator(){
		
		Iterator<String> iterator = list.iterator();
		while(iterator.hasNext()){
			iterator.next();
		}
	}
	
	@Test
	public void forEach(){
		for(String item : list){
			
		}
	}
	
	@Test
	public void forIndex(){
		for(int i = 0; i < count; i++){
			list.get(i);
		}
	}
	
	@Test 
	public void lambda(){
		list.forEach((a) -> {});
	} 
	
	@Test 
	public void lambda2(){
		list.stream().forEach((a) -> {});
	} 
	
	@Test 
	public void lambda3(){
		list.stream().parallel().forEach((a) -> {});
	} 
	
	@Test 
	public void lambda4(){
		list.parallelStream().forEach(a -> {});
	} 
}
